package com.aiyi.education.admin.service.impl;


import cn.hutool.crypto.digest.BCrypt;
import com.aiyi.education.admin.service.IKsAdminRoleService;
import com.aiyi.education.admin.service.IKsAdminService;
import com.aiyi.education.entity.admin.KsAdmin;
import com.aiyi.education.entity.admin.KsAdminRole;
import com.aiyi.education.mapper.admin.KsAdminMapper;
import com.aiyi.education.mapper.admin.KsAdminRoleMapper;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.education.base.Constant;
import com.education.base.ErrorReturnConstant;
import com.education.base.PublicResultConstant;
import com.education.exception.BusinessException;
import com.education.util.ComUtil;
import com.education.util.JWTUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author renyong
 * @email sxgyry@163.com
 * @date
 */
@Service
public class KsAdminRoleServiceImpl extends ServiceImpl<KsAdminRoleMapper, KsAdminRole> implements IKsAdminRoleService {

    @Autowired
    KsAdminRoleMapper ksAdminRoleMapper;

    @Override
    public int deleteByPrimaryKey(Integer roleId) {
        return ksAdminRoleMapper.deleteByPrimaryKey(roleId);
    }

    @Override
    public int insertSelective(KsAdminRole record) {
        return ksAdminRoleMapper.insertSelective(record);
    }

    @Override
    public KsAdminRole selectByPrimaryKey(Integer roleId) {
        return ksAdminRoleMapper.selectByPrimaryKey(roleId);
    }

    @Override
    public int updateByPrimaryKeySelective(KsAdminRole record) {
        return ksAdminRoleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public Map<String, Object> addKsAdminRole(Map<String, Object> map, Object userObject, KsAdminRole record) {
        if (StringUtils.isNotEmpty(record.getRoleName())){
            map.put("result",400);
            map.put("msg",PublicResultConstant.PARAM_ERROR);
            return map;
        }
        this.insertSelective(record);
        map.put("result",200);
        map.put("msg", record);
        return map;
    }

    @Override
    public Map<String, Object> updateKsAdminRole(Map<String, Object> map, Object userObject, KsAdminRole record) {
        if (record.getRoleId()==null){
            map.put("result",400);
            map.put("msg",PublicResultConstant.PARAM_ERROR);
            return map;
        }
        this.updateByPrimaryKeySelective(record);
        map.put("result",200);
        map.put("msg", record);
        return map;
    }

    @Override
    public Map<String, Object> deleteKsAdminRole(Map<String, Object> map, Object userObject, KsAdminRole record) {
        if (record.getRoleId()==null){
            map.put("result",400);
            map.put("msg",PublicResultConstant.PARAM_ERROR);
            return map;
        }
        this.deleteByPrimaryKey(record.getRoleId());
        map.put("result",200);
        map.put("msg", PublicResultConstant.SUCCEED);
        return map;
    }

    @Override
    public Map<String, Object> searchKsAdminRole(Map<String, Object> map, Object userObject, Page<KsAdminRole> pageModel, JSONObject requestJson) {
        QueryWrapper wrapper = new QueryWrapper();
        if (StringUtils.isNotEmpty(requestJson.getString("roleName"))){
            wrapper.like("role_name",requestJson.getString("roleName"));
        }
        wrapper.orderByAsc("order_id");
        List<KsAdminRole> roleList = ksAdminRoleMapper.selectByWrapper(pageModel,wrapper);
        pageModel.setRecords(roleList);
        return map;
    }

}
